#!/bin/bash


EXPECTED_ARGS=1

if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: `basename $0` <run time in sec>"
  exit $E_BADARGS
fi


for i in {0..3}
    do
        CMD="java -jar ../mp1.jar config$i.ini topology.ini "
        echo $CMD 
        FIFO=/tmp/myfifo.$i
        rm -f $FIFO
        mkfifo $FIFO
        eval "($CMD) > $FIFO & "
        pids[$i]=$!
        cat $FIFO | tee $i.log &
	sleep 1 # stagger processes a bit
    done

sleep $1s


for i in "${pids[@]}"
    do
        kill $i
    done
